package api_.Wrapper;


import java.util.ArrayList;
import java.util.Iterator;

public class IntegerDemo
{
    public static void main(String[] args)
    {
        Integer i1 = new Integer(1);
        Integer i2 = new Integer(1);
        System.out.println(i1 == i2);
        System.out.println(i1.equals(i2));

        // valueOf 方法会复用1个字节(-128 ~ 127 ) 范围内的数据，建议使用valueOf()
        Integer i3 = Integer.valueOf(11);
        Integer i4 = Integer.valueOf(11);
        System.out.println(i3 == i4);
        System.out.println(i3.equals(i4));

        // 自动装箱  将 3 装箱为Integer类型
        Integer integer = 3;
        // 自动拆箱，将integer拆箱为int类型
        int m = integer;


        ArrayList arrayList = new ArrayList();
        arrayList.add("1");
        arrayList.add(1);  // 自动装箱为Integer


        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext())
        {
            Object object = iterator.next();
            if(object instanceof Integer)
            {
                Integer integer1 = (Integer) object;
                System.out.println(integer1);
            }
        }
    }
    public static void aVoid()
    {
        int intMax = Integer.MAX_VALUE;
        int intMin = Integer.MIN_VALUE;
        System.out.println(intMax);
        System.out.println(intMin);

        long longMax = Long.MAX_VALUE;
        long longMin = Long.MIN_VALUE;
        System.out.println(longMax);
        System.out.println(longMin);

        // 字符串转换为基本类型   前提是 字符可以转换为对应的值
        String s1 = "11";
        int s1ToInt = Integer.parseInt(s1);
        System.out.println(s1ToInt);
        String s2 = "123.123";
        double s2ToDouble = Double.parseDouble(s2);
        System.out.println(s2ToDouble);
    }
}
